#!/usr/bin/env python
# -*- coding: utf-8 -*-

from core.utils.singleton import singleton
from core import Core
from core.event.mouseevent import MouseEvent


@singleton
class ToolsManager:
    
    ID_EDITOR           = 'editor'
    ID_PROJECT          = 'project'
    ID_CONSOLE          = 'console'
    
    
    def __init__(self,arg=None):
        self._tools={}
    
    
    def addTool(self, tool):
        self._tools[tool.id]=tool
        Core().getMenu().quickMenu('Tools','Plugins','[x]'+tool.name).addEventListener(MouseEvent.MOUSE_CLICK,self.onClick,tool)
        tool.enable()
    
    def onClick(self,e):
        if(e.caller.isCheck()):
            e.arg[0].disable()
        else:
            e.arg[0].enable()
        e.caller.check(not e.caller.isCheck())
    
    def getToolById(self, id):
        return self._tools[id]
        
    def hasTool(self, id):
        return self._tools.has_key(id)

    def getActivedTool(self):
        return self._tools
    
    def getAllTool(self):
        pass

